Configure MySQL
Configure MySQL
MySQL is one of the most widely used open source relational databases. This guide covers both a local install and a cloud hosted option using PlanetScale free tier.
Local Install
Install MySQL
- Download MySQL Community Server from https://dev.mysql.com/downloads/mysql/
- Run the installer for your operating system:
Windows:
- Run MySQL Installer and choose
Developer Defaultas the setup type - Set a root password during the configuration step — note this down
- Leave the default port as
3306
macOS:
- Open a terminal and run:
brew install mysql
- Start the service:
brew services start mysql
- Secure the installation and set a root password:
mysql_secure_installation
Connect via DBeaver
- Open DBeaver and click the
New Database Connectionbutton in the top left - Search for
MySQL, select it, and clickNext - Fill in the connection fields:
Host:localhostPort:3306Database: leave blank for nowUsername:rootPassword: the root password you set during install
- Click
Test Connection— if prompted, download the MySQL JDBC driver - Click
Finish
Cloud Hosted (PlanetScale Free Tier)
- Go to https://planetscale.com and sign up for a free account
- Create a new database, name it
sql101, and select the nearest region - Once created, go to
Connect→Connect with→ chooseGeneral - Copy the connection details shown in the dialog:
Host,Username, andPasswordare displayed in the connect dialogPort:3306
- SSL is required on PlanetScale — in DBeaver open the
SSLtab and enableUse SSLandRequire SSL - Open DBeaver and create a new
MySQLconnection with these details - Click
Test Connection, thenFinish
Creating the Database Schema
Now that the connection is established you can create the database schema found here. MySQL requires a database to exist before running the schema. If you do not already have one, run:
CREATE DATABASE SQL101;
USE SQL101;
Then run the schema script.
Notes
- If the connection is refused on a local install, check MySQL is running:
- Windows: open the
Servicesapp and look forMySQL80— start it if it is stopped - macOS: run
brew services listand confirmmysqlshows asstarted
- Windows: open the
- PlanetScale requires SSL — if DBeaver shows an SSL error, double check the
SSLtab hasUse SSLenabled - Root login may be restricted on some macOS installs — if you cannot connect as
root, create a new user:
CREATE USER 'sqluser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON *.* TO 'sqluser'@'localhost';
- Port
3306in use: stop any conflicting MySQL instances or change the port inmy.cnf